<?php
date_default_timezone_set("Asia/Shanghai");
include 'functions.php';
include 'db.php';//数据库连接
//查询下1、2月份，宝付、网银、环迅、线下充值的金额分别是多少？
$sql = "SELECT SUM(money) as money FROM `ych_account_recharge` where fstatus = 1";

for ($i = 1; $i <= 2; $i++) 
{ 
	$start_time = "2014-0".$i."-01";
	if($i == 2){
		$end_time = "2014-0".$i."-28";
	}else{
		$end_time = "2014-0".$i."-31";
	}
	$start = strtotime($start_time);
	$end = strtotime($end_time);
		
	$where1=" and add_time >='{$start}' and  add_time<='{$end}' and ftype=1 ";
	//宝付
	$baosql = $sql.$where1." and payment =11";
	$row = db_fetch_array($baosql,$conn);
	$baoSum = $row['money'];
		
	//网银
	$chinasql = $sql.$where1." and payment =12";
	$row = db_fetch_array($chinasql,$conn);
	$chinaSum = $row['money'];

	//环迅
	$ipssql = $sql.$where1." and payment =10";
	$row = db_fetch_array($ipssql,$conn);
	$ipsSum = $row['money'];
	
	//线下充值
	$linedownsql = $sql." and add_time >='{$start}' and  add_time<='{$end}' and ftype=2 "; 
	$row = db_fetch_array($linedownsql,$conn);
	$linedownSum = $row['money'];

	$result[] = array(
		'month'=>date('Y-m',$start),
		'baofoo' => $baoSum,
		'china' => $chinaSum,
		'ips' => $ipsSum,
		'line_down' => $linedownSum
	);
} 

?>
<h1>1、2月份，宝付、网银、环迅、线下充值的金额</h1>
<table border="1" style="width: 600px;">
<tr>
<td>月份</td>
<td>宝付</td>
<td>网银</td>
<td>环迅</td>
<td>线下充值</td>
</tr>
<?php foreach($result as $v){?>
<tr>
<td><?php echo $v['month'];?></td>
<td><?php echo $v['baofoo'];?></td>
<td><?php echo $v['china'];?></td>
<td><?php echo $v['ips'];?></td>
<td><?php echo $v['line_down'];?></td>
</tr>
<?php }?>
</table>